package data_access;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import modelo.Medico;

public class MedicosManager
{
	public static Medico getById(int matricula)
	{
		Connection c = ConnectionFactory.getConnection();
		try
		{
			PreparedStatement ps = c
					.prepareStatement("SELECT nombre, apellido, estaActivo FROM Medicos");
			ResultSet rs = ps.executeQuery();

			Medico m = null;
			
			if (rs.next())
			{
				String nombre = rs.getString(1);
				String apellido = rs.getString(2);
				boolean estaActivo = rs.getBoolean(3);
				m = new Medico(estaActivo, apellido, matricula, nombre);
			}
			
			return m;
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		finally
		{
			ConnectionFactory.closeConnection(c);
		}
		return null;
	}

}
